{extend name="base" /}
{block name="header"}
{/block}
{block name="main"}
<form class="layui-form" style="width:80%;" id="formData">
	{$formItem|showFormItem|raw}
	{$buttonForm|showFormBtn|raw}


</form>
{/block}
{block name="script"}
<script type="text/javascript">
	layui.use(['form','layer'],function(){
		var form = layui.form,
				layer = parent.layer === undefined ? layui.layer : top.layer,
				$ = layui.jquery;

		form.on("submit(add)",function(data){
			//弹出loading
			var index = layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
			$.ajax({
				url:"{:url($buttonForm['id'])}",
				data:$('#formData').serialize(),
				type:'post',
				async: false,
				success:function(res) {
					if(res.code == 1) {
						setTimeout(function(){
							if(res.url == "{:url('1')}"){
								top.layer.close(index);
								top.layer.msg(res.msg);
								layer.closeAll("iframe");
								//刷新父页面

								parent.location.reload();
							}
							if(res.url != null || res.url != "{:url('1')}"){
								layer.close(index);
								layer.msg(res.msg);
								location.href = res.url;
							}
						},500);
					} else {
						layer.msg(res.msg);
					}
				}
			});
			return false;
		});

		//格式化时间
		function filterTime(val){
			if(val < 10){
				return "0" + val;
			}else{
				return val;
			}
		}
		//定时发布
		var time = new Date();
		var submitTime = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate())+' '+filterTime(time.getHours())+':'+filterTime(time.getMinutes())+':'+filterTime(time.getSeconds());

	})
</script>
{/block}